package com.ruoyi.planthopper.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.drew.imaging.ImageProcessingException;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.Threads;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.MimeTypeUtils;
import com.ruoyi.detection.domain.DetectionLog;

import com.ruoyi.detection.service.ModelService;


import com.ruoyi.planthopper.domain.*;
import com.ruoyi.planthopper.service.InvestigateService;
import com.ruoyi.planthopper.service.ProvincePlotService;


import com.ruoyi.planthopper.utils.FileTool;
import com.ruoyi.planthopper.utils.ImageInfoTool;
import com.ruoyi.planthopper.utils.ImgDrawCircleTool;
import com.ruoyi.planthopper.utils.ParseString;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @program: base-planthopper-detection-master_202130504106_李航
 * @description:
 * @author: LiHang
 * @create: 2021-09-23 16:48
 **/
@Api("调查信息处理接口")
@ApiResponses({
        @ApiResponse(code = 200,message = "OK",response = ReturnInvestigateInfo.class)
})

@Slf4j
@RestController
public class InvestigateController{

    @Autowired
    private InvestigateService investigateService;

    @Autowired
    public ProvincePlotService provincePlotService;

    @Autowired
    private ModelService modelService;

    /**
     * 存储文件的路径
     */
    @Value("${ruoyi.profile}")
    private String profile;

    /**
     * 模型检测图像处理路径
     */
    @Value("${ruoyi.detectionPlanthopperUrl}")
    private String detectionUrl;

    /**
     * 向数据库插入调查信息（图片信息）
     * 保存原图，缩略图，检测图
     */
    //@ResponseBody
    @ApiOperation(value = "向数据库插入调查信息（图片信息）", notes = "示例:http://192.168.1.217:8180/insertInvestigate\n附带请求头数据\n返回识别结果")
    @PostMapping("/insertInvestigate")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id，不用传入，会返回",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要,可不上传）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
           //@ApiImplicitParam(name = "shootingTime",value="拍摄时间（自动获取，不用上传）",paramType = "query",dataType = "Date"),
            //@ApiImplicitParam(name = "uploadTime",value="上传时间（自动获取，不用上传）",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string")
    })
    public AjaxResult insertInvestigate(InvestigateInfo investigateInfo, @RequestParam("imageName") MultipartFile[] files) throws IOException, ImageProcessingException, ParseException {
        List<ReturnInvestigateInfo> result=new ArrayList<ReturnInvestigateInfo>();
        int continueTime=0;

        //检测地块是否存在，不存在则添加到地块表中
        if(investigateInfo.getPlot()!=null){
            ProvincePlot provincePlot = new ProvincePlot();
            provincePlot.setProvince(investigateInfo.getProvince());
            provincePlot.setCity(investigateInfo.getCity());
            provincePlot.setDistrict(investigateInfo.getDistrict());
            provincePlot.setPlot(investigateInfo.getPlot());
            List<String> selectPlotbyProvince= provincePlotService.selectPlotbyProvince(provincePlot);
            int flag=0;
            for (int i = 0; i < selectPlotbyProvince.size(); i++) {
                if(selectPlotbyProvince.get(i).equals(provincePlot.getPlot())){
                    flag=1;
                }
            }
            if(flag==0){
                provincePlotService.insertProvincePlot(provincePlot);
            }
        }
        //System.out.println(flag);

        for(MultipartFile file:files) {

            if (!file.isEmpty()) {
                investigateInfo.setOriginalFileName(file.getOriginalFilename());
                //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");


                String images = FileUploadUtils.upload(RuoYiConfig.getDetectionPath(), file);
                //为linux服务---------------------------
                String detectionImages = StringUtils.substringAfter(images, "profile");

                File imgFile = new File(profile + detectionImages);
                //为linux服务---------------------------
                //String detectionImages = StringUtils.substringAfter(images, "profile");
                //windows
                //File imgFile = new File(images);
                Date imgShootingTime = ImageInfoTool.ImageShootingTimeDate(imgFile);

                //String imageName = investigateInfo.getDiseaseType() + "_" +
                //        sdf.format(imgShootingTime) + "_" +
                //        investigateInfo.getWeather() + "_" +
                //        investigateInfo.getWindpower() + "_" +
                //        investigateInfo.getTemperature()+ "_" +
                //        investigateInfo.getHumidity() + "_" +
                //        investigateInfo.getProvince() + "_" +
                //        investigateInfo.getCity() + "_" +
                //        investigateInfo.getDistrict() + "_" +
                //        investigateInfo.getPlot() + "_" +
                //        investigateInfo.getInvestigator() + "_" +
                //        investigateInfo.getShootingEquipment() + "__original.jpg";

                String imageName=images;
                //int flag=0;
                //List<String> AllImagePath = investigateService.selectAllImagePath();
                //for (String imagePath : AllImagePath) {
                //    if (imagePath.contains(imageName)) {
                //        flag=1;
                //        continueTime++;
                //        System.out.println(file.getOriginalFilename()+"图片已经上传过了，该图片上传失败");
                //        break;
                //    }
                //}
                //if(flag==1){
                //    continue;
                //}


                String imgCreateTime = FileTool.getImgCreateTime(imgFile);



                /* 解析识别结果构造实例存入数据库并返回, 检测不需要list集合，识别有多个可能，需要集合装载，其他的不需要 */
                List<DetectionLog> detectionLogList = new ArrayList<>();
                ImgDrawCircleTool tool = new ImgDrawCircleTool();

                try {
                    // 图片发送到Django进行识别
                    ResponseEntity<String> responseEntity = Threads.detectionRequest(profile + detectionImages, detectionUrl);
                    log.info("responseEntity------->" + responseEntity.getBody());
                    // json格式的数据转换成数组格式
                    detectionLogList = JSON.parseArray(responseEntity.getBody(), DetectionLog.class);
                    log.info(detectionLogList.toString());
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
                if (detectionLogList.size()!=0) {
                    for (DetectionLog detection : detectionLogList) {
                        if (StringUtils.isNotNull(detection)) {
                            detection.setImagePath(images).setOriginalFileName(file.getOriginalFilename()).setThumPath(images.replace("original", "thum"));
                            System.out.println(detection.getTag());
                            String tagNum = ParseString.getTagNum(detection.getTag());
                            log.info("检测结果：" + tagNum);
                            //detection.getTag()  [2,2,2,2,2,2,2,3,3,2,2,3]
                            //tagNum  {"2":9,"3":3}
                            JSONObject jsonObject = JSON.parseObject(tagNum);
                            int num_1 = 0, num_2 = 0, num_3 = 0, num_4 = 0;
                            if (jsonObject.get("1") != null) {
                                num_1 = (int) jsonObject.get("1");
                            }
                            if (jsonObject.get("2") != null) {
                                num_2 = (int) jsonObject.get("2");
                            }
                            if (jsonObject.get("3") != null) {
                                num_3 = (int) jsonObject.get("3");
                            }
                            if (jsonObject.get("4") != null) {
                                num_4 = (int) jsonObject.get("4");
                            }
                            /*画框之后的结果图 resUrl  缩略图 已添加 */
                            List<String> tagList = JSON.parseArray(detection.getTag(), String.class);
                            //lihang的本地版本
                            //String resultPath = tool.doDrawRectangle(detection.getCorner(), tagList, images, num_1, num_2, num_3, num_4);
                            String resultPath = tool.doDrawRectangle(detection.getCorner(), tagList, profile + detectionImages, num_1, num_2, num_3, num_4).replace(profile, Constants.RESOURCE_PREFIX);

                            detection.setTag(ParseString.getTagNum(detection.getTag())).setResultPath(resultPath).setImgTime(imgCreateTime);
                            log.info(detection.toString());
                            //modelService.insertDetectionLog(detection);

                            //lihang的本地版本
                            //investigateInfo.setImagePath(images);
                            //linux服务器版本
                            //全路径
                            //investigateInfo.setImagePath(profile + detectionImages);
                            investigateInfo.setImagePath(imageName);
                            investigateInfo.setShootingTime(imgShootingTime);
                            investigateInfo.setUploadTime(new Date());
                            investigateInfo.setTag(detection.getTag());
                            InvestigateInfo investigateInfoReturn = investigateService.insertInvestigateInfo(investigateInfo);

                            String ImagePathOld=detection.getImagePath();
                            String path = detection.getImagePath().replace(ImagePathOld.split("/")[ImagePathOld.split("/").length-1],"");
                            String newImagePath=imageName;
                            String newthumPath=newImagePath.replace("original","thum");
                            String newResultPath=newImagePath.replace("original","original__Result");
                            detection.setImagePath(newImagePath);
                            detection.setThumPath(newthumPath);
                            detection.setResultPath(newResultPath);
                            ReturnInvestigateInfo returnInvestigateInfos = new ReturnInvestigateInfo();
                            returnInvestigateInfos.setInvestigator(investigateInfoReturn.getInvestigator());
                            returnInvestigateInfos.setId(investigateInfoReturn.getId());
                            returnInvestigateInfos.setImagePath(investigateInfoReturn.getImagePath());
                            returnInvestigateInfos.setDiseaseType(investigateInfoReturn.getDiseaseType());
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
                            returnInvestigateInfos.setShootingTime(sdf.format(investigateInfoReturn.getShootingTime()));
                            returnInvestigateInfos.setUploadTime(sdf.format(investigateInfoReturn.getUploadTime()));
                            returnInvestigateInfos.setWeather(investigateInfoReturn.getWeather());
                            returnInvestigateInfos.setWindpower(investigateInfoReturn.getWindpower());
                            returnInvestigateInfos.setTemperature(investigateInfoReturn.getTemperature());
                            returnInvestigateInfos.setHumidity(investigateInfoReturn.getHumidity());
                            returnInvestigateInfos.setProvince(investigateInfoReturn.getProvince());
                            returnInvestigateInfos.setCity(investigateInfoReturn.getCity());
                            returnInvestigateInfos.setDistrict(investigateInfoReturn.getDistrict());
                            returnInvestigateInfos.setPlot(investigateInfoReturn.getPlot());
                            returnInvestigateInfos.setInvestigator(investigateInfoReturn.getInvestigator());
                            returnInvestigateInfos.setShootingEquipment(investigateInfoReturn.getShootingEquipment());
                            returnInvestigateInfos.setTag(investigateInfoReturn.getTag());
                            returnInvestigateInfos.setOriginalFileName(investigateInfoReturn.getOriginalFileName());
                            returnInvestigateInfos.setThumPath(investigateInfoReturn.getThumPath());
                            returnInvestigateInfos.setResultPath(investigateInfoReturn.getResultPath());
                            returnInvestigateInfos.setPhone(investigateInfoReturn.getPhone());
                            returnInvestigateInfos.setEarlyOrLateRice(investigateInfoReturn.getEarlyOrLateRice());
                            returnInvestigateInfos.setVarieties(investigateInfoReturn.getVarieties());
                            returnInvestigateInfos.setGrowthPeriod(investigateInfoReturn.getGrowthPeriod());
                            //System.out.println(returnInvestigateInfos.toString());
                            PlanthopperNumType planthopperNumType = json2InsectTypeForOne(returnInvestigateInfos.getTag());
                            returnInvestigateInfos.setPlanthopperNumType(planthopperNumType);
                            returnInvestigateInfos.setAccuracy(detection.getAccuracy());
                            result.add(returnInvestigateInfos);
                        }
                    }


                }else {
                    String resultPath = tool.doDrawEmpty(profile + detectionImages).replace(profile, Constants.RESOURCE_PREFIX);
                    investigateInfo.setImagePath(imageName);
                    investigateInfo.setShootingTime(imgShootingTime);
                    investigateInfo.setUploadTime(new Date());
                    investigateInfo.setTag("{}");
                    InvestigateInfo investigateInfoReturn = investigateService.insertInvestigateInfo(investigateInfo);

                    ReturnInvestigateInfo returnInvestigateInfos = new ReturnInvestigateInfo();
                    returnInvestigateInfos.setInvestigator(investigateInfoReturn.getInvestigator());
                    returnInvestigateInfos.setId(investigateInfoReturn.getId());
                    returnInvestigateInfos.setImagePath(investigateInfoReturn.getImagePath());
                    returnInvestigateInfos.setDiseaseType(investigateInfoReturn.getDiseaseType());
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
                    returnInvestigateInfos.setShootingTime(sdf.format(investigateInfoReturn.getShootingTime()));
                    returnInvestigateInfos.setUploadTime(sdf.format(investigateInfoReturn.getUploadTime()));
                    returnInvestigateInfos.setWeather(investigateInfoReturn.getWeather());
                    returnInvestigateInfos.setWindpower(investigateInfoReturn.getWindpower());
                    returnInvestigateInfos.setTemperature(investigateInfoReturn.getTemperature());
                    returnInvestigateInfos.setHumidity(investigateInfoReturn.getHumidity());
                    returnInvestigateInfos.setProvince(investigateInfoReturn.getProvince());
                    returnInvestigateInfos.setCity(investigateInfoReturn.getCity());
                    returnInvestigateInfos.setDistrict(investigateInfoReturn.getDistrict());
                    returnInvestigateInfos.setPlot(investigateInfoReturn.getPlot());
                    returnInvestigateInfos.setInvestigator(investigateInfoReturn.getInvestigator());
                    returnInvestigateInfos.setShootingEquipment(investigateInfoReturn.getShootingEquipment());
                    returnInvestigateInfos.setTag("{}");
                    returnInvestigateInfos.setOriginalFileName(investigateInfoReturn.getOriginalFileName());
                    returnInvestigateInfos.setThumPath(investigateInfoReturn.getThumPath());
                    returnInvestigateInfos.setResultPath(investigateInfoReturn.getResultPath());
                    returnInvestigateInfos.setPhone(investigateInfoReturn.getPhone());
                    returnInvestigateInfos.setEarlyOrLateRice(investigateInfoReturn.getEarlyOrLateRice());
                    returnInvestigateInfos.setVarieties(investigateInfoReturn.getVarieties());
                    returnInvestigateInfos.setGrowthPeriod(investigateInfoReturn.getGrowthPeriod());
                    //System.out.println(returnInvestigateInfos.toString());
                    //没检测结果的情况
                    PlanthopperNumType PlanthopperNumType = json2InsectTypeForOne(returnInvestigateInfos.getTag());
                    returnInvestigateInfos.setPlanthopperNumType(PlanthopperNumType);

                    result.add(returnInvestigateInfos);
                    //return AjaxResult.success("再试一次");
                }
            }else {
                return AjaxResult.error("上传图片异常");
            }
        }
        if(continueTime==files.length){
            return AjaxResult.success("所有图片均已被添加过");
        }
        return AjaxResult.success(result);
    }


    /**
     * 查询所有的调查信息（图片信息）
     * @return
     */
    @ApiOperation(value = "查询所有的调查信息（图片信息）", notes = "示例:http://192.168.1.217:8180/selectAllInfo\n返回调查信息\n返回信息列表")
    //@ResponseBody
    @GetMapping("/selectAllInfo")
    public AjaxResult selectAllInfo(){

        List<ReturnInvestigateInfo> investigateInfos = investigateService.selectInvestigateInfoAll();
        return AjaxResult.success(investigateInfos);
    }


    /**
     * 查询所有的调查信息（图片信息）(分页版本)
     * @return
     */
    @ApiOperation(value = "查询所有的调查信息（图片信息）(分页版本)", notes = "示例:http://192.168.1.217:8180/selectAllInfoPage\n返回调查信息\n返回信息列表")
    //@ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "第几页",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "pageSize",value = "一页多少数据",paramType = "query",dataType = "string")
    })
    @GetMapping("/selectAllInfoPage")
    public TableDataInfo selectAllInfoPage(Integer pageNum, Integer pageSize){
        //因为在service里返回的类型会经过额外的赋值，导致不能直接调用在SendFrontController中分页的方法
        //所以是选择了使用在service中手写方法的形式来分页
        TableDataInfo tableDataInfo = investigateService.selectInvestigateInfoAllPage(pageNum,pageSize);
        return tableDataInfo;
    }

    /**
     * 根据条件查询全部符合条件的调查信息（图片信息）
     * @return
     */
    @ApiOperation(value = "根据条件查询全部符合条件的调查信息（图片信息）", notes = "示例:http://192.168.1.217:8180/selectInvestigateInfoByCondition\n请求头附带查询条件\n返回信息列表")
    //@ResponseBody
    @PostMapping("/selectInvestigateInfoByCondition")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "beginTime",value="开始时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "endTime",value="结束时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingTime",value="拍摄时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "uploadTime",value="上传时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int")
    })
    public AjaxResult selectInvestigateInfoByCondition(SelectInvestigateInfo selectInvestigateInfo){
        List<ReturnInvestigateInfo> investigateInfosByCondition = investigateService.selectInvestigateInfoByCondition(selectInvestigateInfo);
        return AjaxResult.success(investigateInfosByCondition);
    }

    /**
     * 根据条件查询全部符合条件的调查信息（图片信息）分页
     * @return
     */
    @ApiOperation(value = "根据条件查询全部符合条件的调查信息（图片信息）分页", notes = "示例:http://192.168.1.217:8180/selectInvestigateInfoByConditionPage\n请求头附带查询条件\n返回信息列表")
    //@ResponseBody
    @PostMapping("/selectInvestigateInfoByConditionPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "beginTime",value="开始时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "endTime",value="结束时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingTime",value="拍摄时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "uploadTime",value="上传时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "pageNum",value = "第几页",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "pageSize",value = "一页多少数据",paramType = "query",dataType = "string")
    })
    public TableDataInfo selectInvestigateInfoByConditioPage(SelectInvestigateInfo selectInvestigateInfo,Integer pageNum, Integer pageSize){
        TableDataInfo tableDataInfo = investigateService.selectInvestigateInfoByConditionPage(selectInvestigateInfo, pageNum, pageSize);
        return tableDataInfo;
    }

    /**
     * 根据条件查询全部符合条件的调查人姓名信息
     * @return
     */
    @ApiOperation(value = "根据条件查询全部符合条件的调查人姓名信息", notes = "示例:http://192.168.1.217:8180/selectInvestigatorByCondition\n请求头附带查询条件\n返回信息列表")
    //@ResponseBody
    @PostMapping("/selectInvestigatorByCondition")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "beginTime",value="开始时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "endTime",value="结束时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingTime",value="拍摄时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "uploadTime",value="上传时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int")
    })
    public AjaxResult selectInvestigatorByCondition(SelectInvestigateInfo selectInvestigateInfo){
        List<String> investigators = investigateService.selectInvestigatorByCondition(selectInvestigateInfo);
        return AjaxResult.success(investigators);
    }

    /**
     * 根据条件查询全部符合条件的地块信息
     * @return
     */
    @ApiOperation(value = "根据条件查询全部符合条件的地块信息", notes = "示例:http://192.168.1.217:8180/selectPLotByCondition\n请求头附带查询条件\n返回信息列表")
    //@ResponseBody
    @PostMapping("/selectPLotByCondition")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "beginTime",value="开始时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "endTime",value="结束时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingTime",value="拍摄时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "uploadTime",value="上传时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int")
    })
    public AjaxResult selectPlotByCondition(SelectInvestigateInfo selectInvestigateInfo){
        List<String> investigators = investigateService.selectPlotByCondition(selectInvestigateInfo);
        return AjaxResult.success(investigators);
    }

    /**
     * 根据条件查询调查播报信息（图片信息）
     * @return 返回播报信息，用于展示折线图
     */
    @ApiOperation(value = "根据条件查询调查信息（图片信息）", notes = "示例:http://192.168.1.217:8180/selectTagByCondition\n请求头附带查询条件\n返回播报信息，用于展示折线图")
    //@ResponseBody
    @PostMapping("/selectTagByCondition")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "beginTime",value="开始时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "endTime",value="结束时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingTime",value="拍摄时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "uploadTime",value="上传时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int")
    })
    public AjaxResult selectTagByCondition(SelectInvestigateInfo selectInvestigateInfo) throws ParseException {
        List<BroadcastPlanthopperInfo> broadcastPlanthopperInfo = investigateService.getBroadcastInfo(selectInvestigateInfo);
        return AjaxResult.success(broadcastPlanthopperInfo);
    }



    /**
     * 根据条件查询昆虫信息（图片信息），主要用于查询7天内，或者30日天内或者N天内这种数据
     * days 就是提前几天
     * @return 返回播报信息，用于展示折线图
     */
    @ApiOperation(value = "根据条件查询调查信息（图片信息）,主要用于查询7天内，或者30日天内或者N天内这种数据", notes = "示例:http://192.168.1.217:8180/selectTagBeforeNdays\n请求头附带查询条件以及提前的天数\n返回播报信息，用于展示折线图")
    //@ResponseBody
    @PostMapping("/selectTagBeforeNdays")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "beginTime",value="开始时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "endTime",value="结束时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingTime",value="拍摄时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "uploadTime",value="上传时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "days",value="最近几天的这个几",paramType = "query",dataType = "int")
    })
    public AjaxResult selectTagBeforeNdays(SelectInvestigateInfo selectInvestigateInfo, int days) throws ParseException {
        Calendar now =Calendar.getInstance();
        Date date = new Date();
        now.setTime(date);

        now.set(Calendar.DATE,now.get(Calendar.DATE)-days);

        selectInvestigateInfo.setBeginTime(now.getTime());
        selectInvestigateInfo.setEndTime(date);
        List<BroadcastPlanthopperInfo> broadcastPlanthopperInfo = investigateService.getBroadcastInfo(selectInvestigateInfo);
        return AjaxResult.success(broadcastPlanthopperInfo);
    }

    /**
     * 记录手动记录的害虫数量
     *
     * @return 返回播报信息，用于展示折线图
     */
    @ApiOperation(value = "添加手动记录的害虫数量", notes = "示例:http://192.168.1.217:8180/updateManualTag\n请求头附带查询条件以及提前的天数\n返回播报信息，用于展示折线图")
    //@ResponseBody
    @PostMapping("/updateManualTag")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value="对应的数据id",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int")

    })
    public AjaxResult updateManualTag(PlanthopperNumType PlanthopperNumType, @RequestParam("id") int id) throws ParseException {
        SelectInvestigateInfo selectInvestigateInfo = new SelectInvestigateInfo();
        selectInvestigateInfo.setLongWingedAdult(PlanthopperNumType.getLongWingedAdult());
        selectInvestigateInfo.setShortWingedAdult(PlanthopperNumType.getShortWingedAdult());
        selectInvestigateInfo.setHighInstarLarvae(PlanthopperNumType.getHighInstarLarvae());
        selectInvestigateInfo.setLowInstarLarvae(PlanthopperNumType.getLowInstarLarvae());
        selectInvestigateInfo.setOther(PlanthopperNumType.getOther());
        selectInvestigateInfo.setId(id);
        int i = investigateService.updateManualTag(selectInvestigateInfo);

        return AjaxResult.success(i);
    }

    /**
     * 根据条件查询调查播报信息（图片信息）(百从)
     * @return 返回播报信息，用于展示折线图
     */
    @ApiOperation(value = "根据条件查询调查信息（图片信息）(百从)", notes = "示例:http://192.168.1.217:8989/selectTagByConditionHundred\n请求头附带查询条件\n返回播报信息，用于展示折线图")
    //@ResponseBody
    @PostMapping("/selectTagByConditionHundred")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "beginTime",value="开始时间",paramType = "query",dataType = "string",required=true),
            @ApiImplicitParam(name = "endTime",value="结束时间",paramType = "query",dataType = "string",required=true),
            @ApiImplicitParam(name = "shootingTime",value="拍摄时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "uploadTime",value="上传时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int")
    })
    public AjaxResult selectTagByConditionHundred(SelectInvestigateInfo selectInvestigateInfo) throws ParseException {
        ReturnBroadcastHundred broadcastHundred = investigateService.getBroadcastHundred(selectInvestigateInfo);
        return AjaxResult.success(broadcastHundred);
    }



    /**
     * 根据条件查询昆虫信息（图片信息），主要用于查询7天内，或者30日天内或者N天内这种数据(百从)
     * days 就是提前几天
     * @return 返回播报信息，用于展示折线图
     */
    @ApiOperation(value = "根据条件查询调查信息（图片信息）,主要用于查询7天内，或者30日天内或者N天内这种数据(百从)", notes = "示例:http://192.168.1.217:8989/selectTagBeforeNdaysHundred\n请求头附带查询条件以及提前的天数\n返回播报信息，用于展示折线图")
    //@ResponseBody
    @PostMapping("/selectTagBeforeNdaysHundred")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imageName",value = "上传的图片名",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "id",value = "主键id",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "phone",value="登录用户手机号（不重要）",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "imagePath",value="图片路径（包括图片名）",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "diseaseType",value="病害类型",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "beginTime",value="开始时间",paramType = "query",dataType = "string",required=true),
            @ApiImplicitParam(name = "endTime",value="结束时间",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingTime",value="拍摄时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "uploadTime",value="上传时间",paramType = "query",dataType = "Date"),
            @ApiImplicitParam(name = "weather",value="天气",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "windpower",value="风力",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "temperature",value="温度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "humidity",value="湿度",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "province",value="调查地点 省",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "city",value="调查地点 市",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "district",value="调查地点 区",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "plot",value="地块",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "investigator",value="调查人",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "shootingEquipment",value="拍摄设备",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tag",value="自动识别的昆虫数量信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "tagManual",value="手动输入的害虫信息",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "originalFileName",value="原始图片名",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "thumPath",value="thum图片路径",paramType = "query",dataType = "string"),
            //@ApiImplicitParam(name = "resultPath",value="result图片路径",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "earlyOrLateRice",value="早稻或者晚稻或者更多",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "varieties",value="品种",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "growthPeriod",value="生育期",paramType = "query",dataType = "string"),
            @ApiImplicitParam(name = "longWingedAdult",value="长翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "shortWingedAdult",value="短翅成虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "highInstarLarvae",value="高龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "lowInstarLarvae",value="低龄若虫数量",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "other",value="其他害虫",paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "days",value="最近几天的这个几",paramType = "query",dataType = "int")
    })
    public AjaxResult selectTagBeforeNdaysHundred(SelectInvestigateInfo selectInvestigateInfo, int days) throws ParseException {
        Calendar now =Calendar.getInstance();
        Date date = new Date();
        now.setTime(date);

        now.set(Calendar.DATE,now.get(Calendar.DATE)-days);

        selectInvestigateInfo.setBeginTime(now.getTime());
        selectInvestigateInfo.setEndTime(date);
        ReturnBroadcastHundred broadcastHundred = investigateService.getBroadcastHundred(selectInvestigateInfo);
        return AjaxResult.success(broadcastHundred);
    }

    @RequestMapping("/test")
    public void test(@RequestParam("imageName") MultipartFile file) throws IOException {
        String images = FileUploadUtils.upload(RuoYiConfig.getDetectionPath(), file);
        System.out.println(images);
    }

    /**
     * 获取文件名的后缀
     *
     * @param file 表单文件
     * @return 后缀名
     */
    public static final String getExtension(MultipartFile file)
    {
        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
        if (StringUtils.isEmpty(extension))
        {
            extension = MimeTypeUtils.getExtension(file.getContentType());
        }
        return extension;
    }
    /**
     * 将数据库中的JSON格式转换为对象格式
     * other : 0,
     * 'ccfs': 1,
     * 'glrc': 2,
     * 'dlrc': 3,
     * 'dcfs': 4,
     *
     * @param tag tag
     * @return InsectType类型
     */
    public static PlanthopperNumType json2InsectTypeForOne(String tag) {

        int longWingedAdult = 0;

        int shortWingedAdult = 0;

        int highInstarLarvae = 0;

        int lowInstarLarvae = 0;

        int other = 0;
        //System.out.println(tag);
        JSONObject totalNum = JSON.parseObject(tag);
        if (totalNum.containsKey("1")) {
            longWingedAdult += (Integer) totalNum.get("1");
        }
        if (totalNum.containsKey("4")) {
            shortWingedAdult += (Integer) totalNum.get("4");
        }
        if (totalNum.containsKey("2")) {
            highInstarLarvae += (Integer) totalNum.get("2");
        }
        if (totalNum.containsKey("3")) {
            lowInstarLarvae += (Integer) totalNum.get("3");
        }
        if (totalNum.containsKey("0")) {
            other += (Integer) totalNum.get("0");
        }

        return new PlanthopperNumType(longWingedAdult, shortWingedAdult, highInstarLarvae, lowInstarLarvae, other);
    }


}
